package com.example.ass7.animation;

import java.awt.Color;

import biuoop.DrawSurface;

import com.example.ass7.HighScoresTable;
import com.example.ass7.ScoreInfo;

/**
 * @author Meirav Ben Izhak
 */
public class HighScoresAnimation implements Animation {
    private final HighScoresTable highScoresTable;

    /**
     * @param highScoresTable
     *            highScoresTable
     */
    public HighScoresAnimation(
        HighScoresTable highScoresTable) {
        this.highScoresTable = highScoresTable;
    }

    @Override
    public void doOneFrame(DrawSurface d,
            double dt) {
        d.setColor(new Color(192, 192, 192));
        d.fillRectangle(0, 0, 800, 600);

        drawBorderText(d, new Color(255, 255, 0), 70, 60, "High Scores", 33);

        int xBegin = 130;
        int yBegin = 140;

        drawBorderText(d, Color.GREEN, xBegin, yBegin, "Player Name", 27);

        drawBorderText(d, Color.GREEN, xBegin + 300, yBegin, "Score", 27);
        d.fillRectangle(xBegin, yBegin + 13, 600, 3);
        yBegin = yBegin + 50;

        int size = this.highScoresTable.getHighScores().size();
        int count = 5;
        for (int index = 0; index < count; index++) {
            if (index >= size) {
                break;
            }
            ScoreInfo info = this.highScoresTable
                   .getHighScores().get(index);
            drawBorderText(d, new Color(255, 200, 0),
                    xBegin, yBegin, info.getName(), 27);
            drawBorderText(d, new Color(255, 200, 0),
                    xBegin + 300, yBegin, String.valueOf(info.getScore()), 27);
            yBegin = yBegin + 35;
        }

        String message = "Press space to continue";
        size = 32;
        int x = 200;
        int y = d.getHeight() / 2 + 200;

        d.setColor(Color.black);
        d.drawText(x, y, message, size);
        d.setColor(new Color(23, 136, 208));
        d.drawText(x + 1, y + 1, message, size);
        d.setColor(Color.black);
        d.drawText(x + 3, y + 2, message, size);
    }

    @Override
    public boolean shouldStop() {
        return Boolean.FALSE;
    }

    /**
     * @param d d
     * @param color color
     * @param x x
     * @param y y
     * @param message message
     * @param size size
     */
    private void drawBorderText(DrawSurface d,
            Color color, int x, int y, String message, int size) {
        d.setColor(Color.black);
        d.drawText(x - 1,
                y,
                message,
                size);
        d.drawText(x + 1,
                y,
                message,
                size);
        d.drawText(x,
                y - 1,
                message,
                size);
        d.drawText(x,
                y + 1,
                message,
                size);
        d.setColor(color);
        d.drawText(x,
                y,
                message,
                size);
    }

}
